# 虚拟环境位置 -- D:\virtualENV3.5.2\ENV
# -*- coding: utf-8 -*-
# @Time    : 2017/11/29 19:16
# @Author  : wdm
# @Site    : 
# @File    : get_task.py
# @Software: PyCharm

import redis    # 导入redis模块，通过python操作redis 也可以直接在redis主机的服务端操作缓存数据库

class RedisConnection(object):
    __connection = None
    @staticmethod
    def get_instance():
        if RedisConnection.__connection == None:
            pool = redis.ConnectionPool(host='180.76.149.79', port=6379, decode_responses=True)   # host是redis主机，需要redis服务端和客户端都起着 redis默认端口是6379
            connection = redis.Redis(connection_pool=pool)
            RedisConnection.__connection = connection
        return RedisConnection.__connection


def get_start_url():
    connection = RedisConnection.get_instance();
    data_list = connection.lrange("start_urls",0,0)
    if len(data_list) == 0:
        return None
    connection.lrem("start_urls", data_list[0])
    return data_list[0]

